function e(e) {
    return (e = e.toString())[1] ? e : "0" + e;
}

function O(e, O) {
    if (0 > O || "" === e) return "......";
    for (var n = 10, t = 30, E = S.COURSE, _ = [ 5, n, n, t, 60, 85, 80, 100, 120, 150, 175, 170, 190, 210, 240, 265, 260, 280, 300, 330 ], r = [ 355, 350, t, 60, 80, 95, 100, 120, 150, 170, 185, 190, 210, 240, 260, 275, 280, 300, 330, 350 ], i = 0; i < _.length; i++) if (0 == i || 1 == i) {
        if (r[i] <= e || e <= _[i]) return E[i];
    } else if (_[i] <= e && e <= r[i]) return E[i];
    return e;
}

var S = {
    COURSE: [ "正北向", "北向", "东北向偏北", "东北向", "东北向偏东", "正东向", "东向", "东南向偏东", "东南向", "东南向偏南", "正南向", "南向", "西南向偏南", "西南向", "西南向偏西", "正西向", "西向", "西北向偏西", "西北向", "西北向偏北" ],
    COURSE_NORTH: [ "正北向", "北向" ],
    COURSE_NORTHEAST: [ "东北向偏北", "东北向", "东北向偏东" ],
    COURSE_EAST: [ "正东向", "东向" ],
    COURSE_SOUTHEAST: [ "东南向偏东", "东南向", "东南向偏南" ],
    COURSE_SOUTH: [ "正南向", "南向" ],
    COURSE_SOUTHWEST: [ "西南向偏南", "西南向", "西南向偏西" ],
    COURSE_WEST: [ "正西向", "西向" ],
    COURSE_NORTHWEST: [ "西北向偏西", "西北向", "西北向偏北" ]
}, n = {
    STATIC: {
        key: 0,
        text: "静止"
    },
    MOVIE: {
        key: 1,
        text: "行驶"
    },
    OFFLINE: {
        key: 10,
        text: "离线"
    },
    SLEEP: {
        key: 2,
        text: "休眠"
    }
};

module.exports = {
    formatTime: function(O) {
        var S = O.getFullYear(), n = O.getMonth() + 1, t = O.getDate(), E = O.getHours(), _ = O.getMinutes(), r = O.getSeconds();
        return [ S, n, t ].map(e).join("/") + " " + [ E, _, r ].map(e).join(":");
    },
    getCourse: O,
    getDeviceIconBy: function(e, t, E) {
        var _ = "green", r = "_n_1", i = O(t, E);
        if (-1 !== S.COURSE_NORTH.indexOf(i) ? r = "_n_1" : S.COURSE_NORTHEAST.indexOf(i) > -1 ? r = "_ne_1" : S.COURSE_EAST.indexOf(i) > -1 ? r = "_e_1" : S.COURSE_SOUTHEAST.indexOf(i) > -1 ? r = "_se_1" : S.COURSE_SOUTH.indexOf(i) > -1 ? r = "_s_1" : S.COURSE_SOUTHWEST.indexOf(i) > -1 ? r = "_sw_1" : S.COURSE_WEST.indexOf(i) > -1 ? r = "_w_1" : S.COURSE_NORTHWEST.indexOf(i) > -1 && (r = "_nw_1"), 
        e == n.STATIC.key) _ = "blue"; else if (e == n.MOVIE.key) _ = "green"; else if (e == n.SLEEP.key) _ = "yellow"; else if (e == n.OFFLINE.key) return _ = "white", 
        "white.png";
        return _ + r + ".png";
    }
};